// JavaScript Document
function open_popup(url,popup_name,width,height,left,top){
	window.open(url,popup_name, 'height='+height+', width='+width+', left='+left+',top='+top+',toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');
}

function openEventpage(day, month, year) {
	location.href = '?mod=home&act=event&day='+day+'&month='+month+'&year='+year;
}

function validateEmail(email) {
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value)) {
		return false;
	}
	return true;
}
function checkNumber(number){
	var oldstring = number.value; 
	var newstring = parseFloat(oldstring).toString(); 
	var InpValid=1; 
	if (oldstring.length != newstring.length || newstring == "NaN") { 
		InpValid=0; 
		return false;
	} 
	return true;
}
// sort function - ascending (case-insensitive)
function sortFuncAsc(record1, record2) {
	var value1 = record1.optText.toLowerCase();
	var value2 = record2.optText.toLowerCase();
	if (value1 > value2) return(1);
	if (value1 < value2) return(-1);
	return(0);
}

// sort function - descending (case-insensitive)
function sortFuncDesc(record1, record2) {
	var value1 = record1.optText.toLowerCase();
	var value2 = record2.optText.toLowerCase();
	if (value1 > value2) return(-1);
	if (value1 < value2) return(1);
	return(0);
}

function sortSelect(selectToSort, ascendingOrder) {
	if (arguments.length == 1) ascendingOrder = true;    // default to ascending sort

	// copy options into an array
	var myOptions = [];
	for (var loop=0; loop<selectToSort.options.length; loop++) {
		myOptions[loop] = { optText:selectToSort.options[loop].text, optValue:selectToSort.options[loop].value };
	}

	// sort array
	if (ascendingOrder) {
		myOptions.sort(sortFuncAsc);
	} else {
		myOptions.sort(sortFuncDesc);
	}

	// copy sorted options from array back to select box
	selectToSort.options.length = 0;
	for (var loop=0; loop<myOptions.length; loop++) {
		var optObj = document.createElement('option');
		optObj.text = myOptions[loop].optText;
		optObj.value = myOptions[loop].optValue;
		selectToSort.options.add(optObj);
	}
}
//-- Check validate
function check_empty(object,txtAlert){
	if(object.value == ''){
		alert("Please input "+txtAlert+"!");
		object.focus();
		return false;
	}
	return true;
}
